' Done with this one
ChangesInProgress.Remove stat.Name
End If
Next so
If ChangesInProgress.count = 0 Then
' Once all changes are done, reenable the app
Set ChangesInProgress = Nothing
Call EnablePanel(True)
If TargetState = 0 Then Changed = False
End If
' If this was the final restore on close, close the form
If unloadpending Then Unload Me
End Sub
What's Left to Do?
If you look at the sample code closely, you may get the feeling that the code is somehow not quite complete. You are absolutely correct. The code shown here is a long way from what I would consider commercial-quality code. What's missing?
Error checking. Whereas some of the functions do return values indicating whether an error occurred, they do not provide detailed information on the error. The functions that return objects return Nothing if a failure occurs and also neglect to provide detailed information. There are several approaches you could take to fix this:
- Add an error parameter that is passed by reference that can be set by the called function when an error occurs
- Create a class level ''LastError" style property that can be read to retrieve information about the most recent error
- Raise errors using VB's error-handling mechanism
Timeouts. The utility as it stands will hang in an infinite loop should a service fail to start or stop as requested. The best way to handle this is to provide some sort of timeout. The SERVICE_STATUS structure provides additional information to help you detect if a service start or stop operation error has occurred.
Missing functions. If you review the service API functions, you'll see that quite a few functions were left out. These include API functions for adding